<?php
/**
 * Created by PhpStorm.
 * User: lijie
 * Date: 2018/10/3
 * Time: 13:46
 */
namespace app\api\model;

use think\Model;

class Coupon extends Model{

    protected $autoWriteTimestamp = true;
    protected $createTime = 'ctime';
    protected $updateTime = 'utime';
    protected $dateFormat;
    protected $insert = ['status'=>0];

    /**
     * Notes:  添加优惠券产品
     * Create Date: 2018/10/3
     * Create by :lijie
     */
    public function addCoupon($data)
    {
        return $this->isUpdate(false)->allowField(true)->save($data);
    }

    /**
     * Notes:  删除优惠券产品
     * Create Date: 2018/10/3
     * Create by :lijie
     */
    public function delCoupon($data)
    {
        return $this->isUpdate(true)->save(['status'=>9],['coupon_id'=>$data]);
    }

    /**
     * Notes:  编辑优惠券产品
     * Create Date: 2018/10/3
     * Create by :lijie
     */
    public function editCoupon($data,$where)
    {
        return $this->isUpdate(true)->allowField(true)->save($data,$where);
    }

    /**
     * Notes:  查看优惠券产品
     * Create Date: 2018/10/3
     * Create by :lijie
     */
    public function couponList($data,$pagenum,$listNum)
    {
        return $this->where($data)->order("ctime desc")->page($pagenum,$listNum)->select();
    }

    /**
     * Notes:  优惠券产品详情
     * Create Date: 2018/10/3
     * Create by :lijie
     */
    public function couponInfo($param)
    {
        return $this->where($param)->find();
    }
}